<?php
/**
 * Controller used for ajax requests
 * 
 * @package disputeo
 * @version 1.0
 * @author jimmy.dixon
 */

class AjaxController extends Zend_Controller_Action
{
    /**
     * Initialise ajax context property
     */
    public function init()
    {
        $this->_ajax = $this->_helper->getHelper('AjaxContext');
    }
    
    /**
     * Handles ajax username available requests
     */
    public function usernameAction()
    {
        $value = $this->getRequest()->getParam('value');
        $form = new Application_Form_Register();
        $form->isValid(array('username' => $value));
        $errors = $form->getErrors();
        $this->view->available = empty($errors['username']);
        $this->_ajax->addActionContext('username', 'html')->initContext();
    }

}

